var IDLE    = 0;
var STOPPED = 1;
var STARTED = 2;

function SeenLetters() {
    this.length = 0;
}

function Adedanha() {
    this.seenLetters = new SeenLetters();
    this.state       = IDLE;
};

Adedanha.prototype = {
    start : function() {
        this.state = STARTED;
    },
    stop : function() {
        this.state = STOPPED;
    },
    reset : function () {
        this.state = IDLE;

        for ( var seenLetter in this.seenLetters ) {
            var element;
            if ( element = document.getElementById( seenLetter ) ) {
                element.innerHTML = '_';
            }
        }

        this.seenLetters = new SeenLetters();
    },
    changeLetter : function () {
        if ( this.state != STARTED ) {
            return false;
        }

        var letter = new String();

        // Gets the next letter
        while ( true ) {
            if ( this.seenLetters.length > 25 ) {
                this.stop();
                return;
            }

            letter = String.fromCharCode( 65 + Math.round(Math.random() * 25) )

            if ( this.seenLetters[letter] == null ) {
                this.seenLetters.length++;

                // Store the letter to not repeat
                this.seenLetters[letter] = true;
                break;
            }

        }

        // Chage letter
        document.getElementById( letter ).innerHTML = letter;

        return letter;
    }
};

